#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        hash[0] = 1;
        int num = 0, ret = 0;
        for (const auto& e : nums)
        {
            num += e;
            if (hash.count(num - k)) ret += hash[num - k];
            hash[num] ++;
        }
        return ret;
    }
};